﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="album_list.aspx.cs" Inherits="Album_album_list" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <Custom:Header runat="server" />
    <style>
        .pupbox{width:300px;padding:20px;}
    </style>
    <script type="text/javascript">
        $(function() {
            $("a:contains(添加)").click(function() {
                return false;
            }).wBox({
                title: "添加相册",
                html: "<div class='pupbox'>相册名称：<input name='albumname' /><input type='button' class='btnsave' value='保存' /></div>",
                show: false,
                callBack: function() {
                    $(".btnsave").click(function() {
                        $.ajax({
                            url: "action.aspx",
                            dataType: "json",
                            data: { action: "album_add", albumname: $("input[name=albumname]").val() },
                            success: function(data) {
                                if (data.succ) {
                                   
                                    location = '?'
                                } else {
                                    alert(data.msg)
                                }
                            },
                            error: function(req) {
                                alert("抱歉，提交发生意外。");
                            },
                            beforeSend: function() {

                            },
                            complete: function() {

                            }
                        });
                    });
                }
            });

            var aid = 0;
            var wbox = $(".alb-edit").click(function() {
                aid = $(this).attr("aid")
            }).wBox({
                title: "修改相册名称",
                html: "<div class='pupbox'>相册名称：<input name='albumname' /><input type='button' class='btnsave' value='保存' /></div>",
                show: false,
                callBack: function() {
                    var albn = $("input[name=albumname]");
                    albn.val($.trim($("td[aid=" + aid + "]").text()))
                    $(".btnsave").click(function() {
                        $.ajax({
                            url: "action.aspx",
                            dataType: "json",
                            data: { action: "album_edit", aid: aid, albumname: albn.val() },
                            success: function(data) {
                                if (data.succ) {
                                    $("td[aid=" + aid + "]").text(albn.val());
                                    alert("保存成功。");
                                    wbox.close();
                                } else {
                                    alert(data.msg)
                                }
                            },
                            error: function(req) {
                                alert("提交发生意外。");
                            },
                            beforeSend: function() {

                            },
                            complete: function() {

                            }
                        });
                    });
                }

            });

            $("a:contains(删除)").click(function() {
                var ids = "";
                $("input[name=checkboxid]:checked").each(function() {
                    ids += $(this).val() + ","
                });
                if (ids == "") {
                    alert("未选中任何待删除记录");
                } else {
                    $.ajax({
                        url: "action.aspx",
                        dataType: "json",
                        data: { action: "del", ids: ids },
                        success: function(data) {
                            if (data.succ) {
                                $("input[name=checkboxid]:checked").each(function() {
                                    $("td[aid=" + $(this).val() + "]").parent().remove();
                                });

                            } else {
                                alert(data.msg);
                            }
                        },
                        error: function(req) {
                            alert("提交发生意外。");
                        },
                        beforeSend: function() {

                        },
                        complete: function() {

                        }
                    });
                }
                return false;
            });

        })
    </script>
</head>
<body>
    <form runat="server">
        <Custom:ToolBar ID="ToolBar" runat="server" />
        <table  border="0" class="tabList" align="center" cellpadding="0" cellspacing="1">
        <tr class="tbhead">
            <td width="60" align=center>
                全<input type="checkbox" id="chkall" />选
            </td>
            <td>
               相册名称
            </td>
            <td>图片数量</td>
            <td>
                封面
            </td>
            <td>操作</td>
        </tr>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <tr>
                <td>
                    <div align="center">
                        <input name="checkboxid" type="checkbox" value="<%#Eval("ID") %>" />
                    </div>
                </td>
                <td aid="<%#Eval("id") %>">
                   <%#Eval("albumName")%>
                </td>
                <td><%#Eval("imgcount") %></td>
                <td><%#Eval("conver") %></td>
                <td>
                    <a class="alb-edit" href="#" aid="<%#Eval("id") %>">修改</a> / <a href="img_list.aspx?id=<%#Eval("id") %>">图片</a>
                </td>
            </tr>
            </ItemTemplate>
        </asp:Repeater>
    </table>
   </form>
</body>
</html>
